<?php
namespace app\index\controller;

use think\View;
use think\Validate;
use think\Session;
use think\Controller;
use think\Db;
require_once APP_VENDOR.'Aliyunsms/api/Sms.php';


class Register extends Controller{

    //登录页
    public function index()
    {   
    	$view = new View();
        return $view->fetch();
    }
    
    public function doRegister(){
        $r_verify   = Session::get('verify'); //手机验证码
        $u_verify   = input('verify'); // 用户验证码

        $user_info['mobile']      = input('mobile');
        $user_info['give_time']   = time();
        $user_info['share_num']   = createNonceStr(6);
        if($r_verify != $u_verify ){
            $this->error('验证码不正确！');die;
        }
        //判断该手机号是否被注册
        if(Db::name('user')->where('mobile',$user_info['mobile'])->find()){
            $this->error('该手机号已被注册！');die;
        }
     
        
        $user_info['now_number']  = 2;//首次注册赠送两次抽奖次数
        $user_info['create_time'] = time();

        Db::name('user')->insert($user_info);//添加一条用户记录
        
        Session::set('user_mobile',$user_info['mobile']);

        $this->success('注册成功！', 'Index/index');
        
    }



}
